<template>
  <div class="box">
    <h2>B组件,{{ num }}</h2>
    <el-button type="primary" size="default" @click="handleAdd">
      新增商品
    </el-button>
    <div v-for="item in filterGoods">
      商品名称{{ item.name }} 价格{{ item.price }}
    </div>
  </div>
</template>

<script>
export default {
  computed: {
    num() {
      return this.$store.state.counter.num;
    },
    filterGoods() {
      // let obj = {'my-name':'三丰'}
      // obj['my-name']
      return this.$store.getters["goods/filterGoods"]; //getters数据也必须在computed中提取
    },
  },
  methods: {
    handleAdd() {
      this.$store.commit("goods/addGoodsMut", {
        name: "新商品",
        price: Math.round(Math.random() * 700 + 300),
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  border: 1px solid #333;
  height: 500px;
  width: 50%;
}
</style>
